import * as CryptoJS from 'crypto-js'
import { AES } from '@constants/aes'

export const enCryptoAES = (value: string) => {
  return CryptoJS.AES.encrypt(value, AES.KEY, {
    iv: AES.IV,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  }).ciphertext.toString()
}

export const deCryptoAES = (value: string) => {
  const _value = CryptoJS.enc.Hex.parse(value)
  value = CryptoJS.enc.Base64.stringify(_value)
  return CryptoJS.AES.decrypt(value, AES.KEY, {
    iv: AES.IV,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  }).toString(CryptoJS.enc.Utf8)
}
